import store from "@/store/index.js";

export function get(baseUrl, url, params) {
	var token = uni.getStorageSync("token");
	return new Promise((resolve, reject) => {
		uni.request({
			data: params,
			url: baseUrl + url,
			method: "GET",
			header: {
				"X-Access-Token": token,
			},
			timeout: 10000,
			success: (res) => {
				resolve(res);
			},
			fail: (err) => {
				uni.showToast({
					title: "请检查网络连接",
					duration: 2000,
					icon: "none",
					success: function(res) {
						reject(err);
					},
				});
			},
		});
	});
}
export function post(baseUrl, url, params) {
	var token = uni.getStorageSync("token");
	return new Promise((resolve, reject) => {
		uni.request({
			data: params,
			url: baseUrl + url,
			method: "POST",
			header: {
				"X-Access-Token": token,
			},
			timeout: 10000,
			success: (res) => {
				resolve(res);
			},
			fail: (err) => {
				uni.showToast({
					title: "请检查网络连接",
					duration: 2000,
					icon: "none",
					success: function(res) {
						reject(err);
					},
				});
			},
		});
	});
}
export function put(baseUrl, url, params) {
	var token = uni.getStorageSync("token");
	return new Promise((resolve, reject) => {
		uni.request({
			data: params,
			url: baseUrl + url,
			method: "PUT",
			header: {
				"X-Access-Token": token,
			},
			timeout: 10000,
			success: (res) => {
				resolve(res);
			},
			fail: (err) => {
				uni.showToast({
					title: "请检查网络连接",
					duration: 2000,
					icon: "none",
					success: function(res) {
						reject(err);
					},
				});
			},
		});
	});
}
